﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace UniversalQueryDemo
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.FillListView("");
        }

        private void FillListView(string strWhere)
        {
            this.listView1.Items.Clear();
            List<Person> pl = Person.GetPersonList(strWhere);
            if (pl.Count < 1)
                return;
            for (int i = 0; i < pl.Count; i++)
            {
                ListViewItem item = this.listView1.Items.Add((i + 1).ToString());
                item.SubItems.Add(pl[i].Name);
                item.SubItems.Add(pl[i].Company);
                item.SubItems.Add(pl[i].Occupation);
                item.SubItems.Add("$" + ((float)pl[i].Salary).ToString("#,###.##"));
                item.SubItems.Add(pl[i].Height);
            }
        }

        private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {
            this.universalQuery1.ShowDialog();
        }

        private void universalQuery1_AfterDoQueryClicked(object sender, cn.Laiyunqing.WinControls.DoQueryEventArgs args)
        {
            //do query after query clicked
            if (args.QueryString == string.Empty)
                return;
            this.FillListView("  where "+args.QueryString);
        }

        private void toolStripMenuItem2_Click(object sender, EventArgs e)
        {
            this.FillListView("");
        }
    }
}
